/**
 * orders路由模块
 * routes\orders.js
 */
var express = require('express');
var router = express.Router();  
const config = require("../common/config");
const orders = require("../controller/orders");

// 支付链接生成接口
router.post('/pay', orders.gopay);
router.post('/notify', orders.handleAlipayNotify);
/**
 * @swagger
 * /orders/add:
 *   post:
 *     tags:
 *       - orders
 *     summary: 新增订单
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               buyer_id:
 *                 type: string
 *                 example: 20220202222
 *               item_id:
 *                 type: integer
 *                 example: 1
 *     responses:
 *       201:
 *         description: 订单添加成功
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器内部错误
 */
router.post('/add', orders.addorders);

/**
 * @swagger
 * /orders/updateorders:
 *   put:
 *     tags:
 *       - orders
 *     summary: 设置订单状态
 *     description: 修改指定订单状态为：待发货/ 待收货 / 已完成
 *     parameters:
 *       - in: query
 *         name: order_id
 *         required: true
 *         schema:
 *           type: integer
 *           format: int32
 *         example: 1
 *         description: 要更新的订单ID
 *       - in: query
 *         name: order_status
 *         required: true
 *         schema:
 *           type: integer
 *           enum: [0, 1, 2]
 *           default: 1
 *         example: 1
 *         description: 目标状态（0-待发货，1-待收货, 2-已完成）
 *     responses:
 *       200:
 *         description: 状态设置成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 msg:
 *                   type: string
 *                   example: "设置商品1状态为1成功"
 *                 data:
 *                   type: array
 *                   example: []
 *                   description: 预留字段，目前返回空数组
 *       400:
 *         description: 参数错误（如缺少必要参数或状态值非法）
 *       404:
 *         description: 商品不存在
 *       500:
 *         description: 服务器内部错误
 */
router.put('/updateorders' ,orders.updateorders);
//根据order_id查询
/**
  * @swagger
  * /orders/getByorderid/{orderid}:
  *   get:
  *     tags:
  *       - orders
  *     summary: 通过orderid查询订单
  *     parameters:
  *       - in: path
  *         name: orderid
  *         required: true
  *         schema:
  *           type: integer
  *     responses:
  *       200:
  *         description: 成功获取订单信息
  *       404:
  *         description: 订单未找到
  *       500:
  *         description: 服务器内部错误
  */
 router.get('/getByorderid/:orderid',orders.getByorderid);

//根据buyer_id查询
/**
  * @swagger
  * /orders/getBybuyerid/{buyerid}:
  *   get:
  *     tags:
  *       - orders
  *     summary: 通过buyerid查询订单
  *     parameters:
  *       - in: path
  *         name: buyerid
  *         required: true
  *         schema:
  *           type: string
  *     responses:
  *       200:
  *         description: 成功获取订单信息
  *       404:
  *         description: 订单未找到
  *       500:
  *         description: 服务器内部错误
  */
router.get('/getBybuyerid/:buyerid',orders.getBybuyerid);

//根据sellerid查询
/**
  * @swagger
  * /orders/getBysellerid/{sellerid}:
  *   get:
  *     tags:
  *       - orders
  *     summary: 通过sellerid查询订单
  *     parameters:
  *       - in: path
  *         name: sellerid
  *         required: true
  *         schema:
  *           type: string
  *     responses:
  *       200:
  *         description: 成功获取订单信息
  *       404:
  *         description: 订单未找到
  *       500:
  *         description: 服务器内部错误
  */
router.get('/getBysellerid/:sellerid',orders.getBysellerid);

//删除一条订单记录
/**
 * @swagger
 * /orders/remove/{orderid}:
 *   delete:
 *     tags:
 *       - orders
 *     summary: 删除一条订单记录
 *     description: 根据订单ID删除指定的订单记录
 *     parameters:
 *       - in: path
 *         name: orderid
 *         required: true
 *         description: 要删除的订单ID
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 成功删除订单信息
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 message:
 *                   type: string
 *                   example: "订单删除成功"
 *       404:
 *         description: 未找到指定ID的订单
 *       500:
 *         description: 服务器内部错误，删除操作失败
 */
router.delete('/remove/:orderid', orders.remove);

router.post('buynow', orders.buyNow);

module.exports = router;



